package net.expectx.pay.test.controller;

import com.github.wxpay.sdk.WXPayConfig;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 * @author Administrator
 */
public class WeiXinPayConfig implements WXPayConfig {
    private String  appId = "wxf85041afbb2c44b8";
    private String  mchId = "1544498151 ";
    private String  key = "d131c0fb7bbe4ec887fcdf5890e91ab9";
    private String  certPath = "C:\\1544498151_20190716_cert\\apiclient_cert.p12";

    private byte[] certData;
    private static WeiXinPayConfig INSTANCE;

    private WeiXinPayConfig() throws Exception {
        File file = new File(certPath);
        InputStream certStream = new FileInputStream(file);
        this.certData = new byte[(int) file.length()];
        certStream.read(this.certData);
        certStream.close();
    }

    public static WeiXinPayConfig getInstance() throws Exception {
        if (INSTANCE == null) {
            synchronized ( WeiXinPayConfig.class) {
                if (INSTANCE == null) {
                    INSTANCE = new WeiXinPayConfig();
                }
            }
        }
        return INSTANCE;
    }
    @Override
    public String getAppID() {
        return appId;
    }
    @Override
    public String getMchID() {
        return mchId;
    }
    @Override
    public String getKey() {
        return key;
    }
    @Override
    public InputStream getCertStream() {
        ByteArrayInputStream certBis;
        certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }

    @Override
    public int getHttpConnectTimeoutMs() {
        return 2000;
    }
    @Override
    public int getHttpReadTimeoutMs() {
        return 10000;
    }
}
